# frozen_string_literal: true

class CreateRuleSetRules < ActiveRecord::Migration[6.0]
  def change
    create_table :rule_set_rules do |t|
      t.integer :rule_set_id,     null: false,  limit: 8
      t.integer :rule_entity_id,  null: false,  limit: 8
      t.integer :ordinal,         null: false,  limit: 4
      t.timestamps                null: false
    end

    add_index :rule_set_rules, %i[rule_set_id rule_entity_id], unique: true
    add_index :rule_set_rules, %i[ordinal rule_set_id], unique: true
    add_foreign_key :rule_set_rules, :rule_entities,
                    column: :rule_set_id,
                    name: 'fk_rule_set_rules_rule_set_id'
    add_foreign_key :rule_set_rules, :rule_entities,
                    name: 'fk_rule_set_rules_rule_id'
  end
end
